package com.xhui.vimarket.zkplus.zul.attr;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.zkoss.zk.ui.util.GenericForwardComposer;

import com.xhui.vimarket.zkplus.zul.attr.bean.AttrInst;
import com.xhui.vimarket.zkplus.zul.attr.bean.AttrWind;
import com.xhui.vimarket.zkplus.zul.attr.bean.impl.AttrTmplImpl;
import com.xhui.vimarket.zkplus.zul.attr.bean.impl.AttrWindImpl;

/**
 * 属性demo composer.
 * 
 * @版权：福富软件 版权所有 (c) 2011
 * @author wuyx
 * @version Revision 1.0.0
 * @see:
 * @创建日期：2011-1-23
 * @功能说明：
 * 
 */
public class AttrDemoComper extends GenericForwardComposer {
    
    /**
     * serialVersionUID.
     */
    private static final long   serialVersionUID = 1L;
    
    /**
     * logger.
     */
    static Logger               logger           = Logger.getLogger(AttrDemoComper.class);
    
    /**
     * attrBox.
     */
    private AttrExt             attrBox;
    
    /**
     * attrInstList.
     */
    private ArrayList<AttrInst> attrInstList     = new ArrayList<AttrInst>();
    
    /**
     * onDisp.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onDisp() {
        final AttrWind attrSpec = this.getAttrSpec();
        this.attrBox.setAttrSpec(attrSpec);
        this.attrBox.display();
    }
    
    /**
     * onDisp2tab.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onDisp2tab() {
        final AttrWind attrSpec = this.getAttrSpec2tab();
        this.attrBox.setAttrSpec(attrSpec);
        this.attrBox.display();
    }
    
    /**
     * getAttrSpec.
     * 
     * @author wuyx
     * @return AttrWind
     * 2011-1-23 wuyx 
     */
    public AttrWind getAttrSpec() {/*
        final AttrWind attrSpec = new AttrWindImpl();
        
        // panel
        final AttrTmplImpl t1 = new AttrTmplImpl();
        t1.setName("测试Pannel");
        t1.setDisplayMode(AttrTmplImpl.MODE_PANEL);
        
        final ArrayList list = new ArrayList();
        
        final ArrayList modeList = new ArrayList();
        modeList.add(AttrTmplImpl.MODE_LABEL);
        modeList.add(AttrTmplImpl.MODE_TEXT);
        modeList.add(AttrTmplImpl.MODE_INT);
        modeList.add(AttrTmplImpl.MODE_DATETIME);
        modeList.add(AttrTmplImpl.MODE_PASSWORD);
        modeList.add(AttrTmplImpl.MODE_DATE);
        modeList.add(AttrTmplImpl.MODE_DATE);
        
         * modeList.add(AttrTmpl.MODE_COMBOBOX);
         * modeList.add(AttrTmpl.MODE_BANDBOX);
         * modeList.add(AttrTmpl.MODE_SELECTLIST);
         * modeList.add(AttrTmpl.MODE_CHECKBOX);
         * modeList.add(AttrTmpl.MODE_RADIO);
         
        int i = 0;
        for (; i < modeList.size(); i++) {
            final int y = i / 4 + 1;
            final int x = i % 4 + 1;
            AttrDemoComper.logger.debug("cx:" + x + ",cy:" + y);
            final String mode = modeList.get(i) + "";
            final AttrTmplImpl t11 = new AttrTmplImpl();
            t11.setName("测试" + mode);
            t11.setDisplayMode(mode);
            t11.setAttrId(i + 10);
            t11.setXAddr(x);
            t11.setYAddr(y);
            list.add(t11);
        }
        // multi
        final AttrTmplImpl tm11 = new AttrTmplImpl();
        tm11.setName("测试" + AttrTmplImpl.MODE_MULTISUB);
        tm11.setDisplayMode(AttrTmplImpl.MODE_MULTISUB);
        tm11.setAttrId(100 + 10);
        tm11.setXAddr(4);
        tm11.setYAddr(2);
        
        final ArrayList list2 = new ArrayList();
        for (int j = 1; j < 2; j++) {
            final int y = j / 4 + 1;
            final int x = j % 4;
            AttrDemoComper.logger.debug("cx:" + x + ",cy:" + y);
            final String mode = modeList.get(j) + "";
            final AttrTmplImpl t11 = new AttrTmplImpl();
            t11.setName("测试" + mode);
            t11.setDisplayMode(mode);
            t11.setAttrId(j + 200);
            t11.setXAddr(x);
            t11.setYAddr(y);
            list2.add(t11);
        }
        tm11.setAttrTmplList(list2);
        
        list.add(tm11);
        
        t1.setAttrTmplList(list);
        
        attrSpec.setAttrTmpl(t1);
        
        return attrSpec;
    */
    	return null;
    }
    
    /**
     * getAttrSpec2tab.
     * 
     * @return AttrWind
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public AttrWind getAttrSpec2tab() {/*
        final AttrWind attrSpec = new AttrWindImpl();
        
        // tree
        final AttrTmplImpl t0 = new AttrTmplImpl();
        t0.setName("测试tree");
        t0.setDisplayMode(AttrTmplImpl.MODE_TREETAB);
        
        // panel
        final AttrTmplImpl t1 = new AttrTmplImpl();
        t1.setName("测试tree");
        t1.setDisplayMode(AttrTmplImpl.MODE_PANEL);
        
        final ArrayList list = new ArrayList();
        
        final ArrayList modeList = new ArrayList();
        modeList.add(AttrTmplImpl.MODE_LABEL);
        modeList.add(AttrTmplImpl.MODE_TEXT);
        modeList.add(AttrTmplImpl.MODE_INT);
        modeList.add(AttrTmplImpl.MODE_DATETIME);
        modeList.add(AttrTmplImpl.MODE_PASSWORD);
        modeList.add(AttrTmplImpl.MODE_DATE);
        modeList.add(AttrTmplImpl.MODE_DATE);
        
         * modeList.add(AttrTmpl.MODE_COMBOBOX);
         * modeList.add(AttrTmpl.MODE_BANDBOX);
         * modeList.add(AttrTmpl.MODE_SELECTLIST);
         * modeList.add(AttrTmpl.MODE_CHECKBOX);
         * modeList.add(AttrTmpl.MODE_RADIO);
         
        int i = 0;
        for (; i < modeList.size(); i++) {
            final int y = i / 4 + 1;
            final int x = i % 4 + 1;
            AttrDemoComper.logger.debug("cx:" + x + ",cy:" + y);
            final String mode = modeList.get(i) + "";
            final AttrTmplImpl t11 = new AttrTmplImpl();
            t11.setName("测试" + mode);
            t11.setDisplayMode(mode);
            t11.setAttrId(i + 10);
            t11.setXAddr(x);
            t11.setYAddr(y);
            list.add(t11);
        }
        // multi
        final AttrTmplImpl tm11 = new AttrTmplImpl();
        tm11.setName("测试" + AttrTmplImpl.MODE_MULTISUB);
        tm11.setDisplayMode(AttrTmplImpl.MODE_MULTISUB);
        tm11.setAttrId(100 + 10);
        tm11.setXAddr(4);
        tm11.setYAddr(2);
        
        final ArrayList list2 = new ArrayList();
        for (int j = 1; j < 2; j++) {
            final int y = j / 4 + 1;
            final int x = j % 4;
            AttrDemoComper.logger.debug("cx:" + x + ",cy:" + y);
            final String mode = modeList.get(j) + "";
            final AttrTmplImpl t11 = new AttrTmplImpl();
            t11.setName("测试" + mode);
            t11.setDisplayMode(mode);
            t11.setAttrId(j + 200);
            t11.setXAddr(x);
            t11.setYAddr(y);
            list2.add(t11);
        }
        tm11.setAttrTmplList(list2);
        
        list.add(tm11);
        
        t1.setAttrTmplList(list);
        
        final ArrayList list0 = new ArrayList();
        list0.add(t1);
        t0.setAttrTmplList(list0);
        attrSpec.setAttrTmpl(t0);
        
        return attrSpec;
    */
    	//xhuipinbi
    	return null;
    }
    
    /**
     * onGetAttrInst.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onGetAttrInst() {
        final ArrayList<AttrInst> list = this.attrBox.getAttrInst();
        AttrDemoComper.logger.debug(list.size());
        this.attrInstList = list;
    }
    
    /**
     * onSetAttrInstAsdef.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onSetAttrInstAsdef() {
        final ArrayList<AttrInst> list = this.attrInstList;
        AttrDemoComper.logger.debug(list.size());
        this.attrInstList = list;
        this.attrBox.setAttrInst(list, true);
    }
    
    /**
     * onReset.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onReset() {
        this.attrBox.reset();
    }
    
    /**
     * onSetAttrInst.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onSetAttrInst() {
        final ArrayList<AttrInst> list = this.attrInstList;
        AttrDemoComper.logger.debug(list.size());
        this.attrInstList = list;
        this.attrBox.setAttrInst(list);
    }
    
    /**
     * onCleanAttrInst.
     * 
     * @author wuyx
     * 2011-1-23 wuyx 
     */
    public void onCleanAttrInst() {
        AttrDemoComper.logger.debug("demo clean");
        this.attrBox.clean();
    }
}
